import RequestIntance from "../net/Request";

export default class Control {

    protected urls: any[];

    constructor() {
        this.urls = [];

        this.initData();
    }

    /**
     * 初始化数据
     */
    protected initData(): void {

    }

    /**
     * 请求成功
     * @param res 
     */
    protected onRequestComplete(res: any): void {

    }

    /**
     * 请求失败
     * @param res 
     */
    protected onRequestError(res: any): void {

    }

    requset() {
        let requests = Array.from({ length: this.urls.length }).map((value, index) => {
            return RequestIntance.request(this.urls[index]);
        })

        return Promise.all(requests).then((res: any) => {
            this.onRequestComplete(res);
        }, (res: any) => {
            this.onRequestError(res);
        })
    }


}